//
//  WBHomeViewController.swift
//  Weibo-Swift
//
//  Created by law on 2018/6/1.
//  Copyright © 2018年 JKing. All rights reserved.
//

import UIKit

private let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {

    /// 微博数据数组
    private lazy var statusList = [StatusModel]()
    
    @objc private func showFriends() {
        
        let vc = TestViewController()
        navigationController?.pushViewController(vc, animated: true)
    }

    override func refresh() {
        
        StatusModel.getHomeStatuses { (response: WBValueResponse<[StatusModel]>)->Void in
            
            self.statusList = response.value!
            self.refreshControl?.endRefreshing()
            self.tableView?.reloadData()
        }
        
    }
    
}

// MARK: - tableView 数据源方法
extension WBHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier:cellId, for: indexPath)
        cell.textLabel?.text = statusList[indexPath.row].text
        return cell
    }
}

extension WBHomeViewController {
    
    @objc override func setupTableView() {
        super.setupTableView()
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
        
    }
    
}
